package com.jcl.recruit.console.mapper.provider;

import com.jcl.recruit.console.model.ConsoleCorpInfo;
import com.jcl.recruit.mapper.provider.SqlProvider;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @ClassName ConsoleCorpInfoProvider

 * @Author yyliu
 * @Date 2018/12/13 16:54
 * @Version 1.0
 **/
public class ConsoleCorpInfoProvider implements SqlProvider<ConsoleCorpInfo> {

    private static final String TABLE_NAME = "t_corp_info";

    public String insert(ConsoleCorpInfo entity) {
        BEGIN();
        INSERT_INTO(TABLE_NAME);
        if (entity.getCode() != null) {
            VALUES("code", "#{code,jdbcType=VARCHAR}");
        }

        if (entity.getFullName() != null) {
            VALUES("full_name", "#{fullName,jdbcType=VARCHAR}");
        }

        if (entity.getShortName() != null) {
            VALUES("short_name", "#{shortName,jdbcType=VARCHAR}");
        }

        if (entity.getEmail() != null) {
            VALUES("email", "#{email,jdbcType=VARCHAR}");
        }

        if (entity.getTelephone() != null) {
            VALUES("telephone", "#{telephone,jdbcType=VARCHAR}");
        }

        if (entity.getMealPackage() != null) {
            VALUES("meal_package", "#{mealPackage,jdbcType=VARCHAR}");
        }

        if (entity.getRegisterDate() != null) {
            VALUES("register_date", "#{registerDate,jdbcType=TIMESTAMP}");
        }

        if (entity.getAbateDate() != null) {
            VALUES("abate_date", "#{abateDate,jdbcType=TIMESTAMP}");
        }

        if (entity.getAddUser() != null) {
            VALUES("add_user", "#{addUser,jdbcType=VARCHAR}");
        }

        if (entity.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }

        if (entity.getUpdateTime() != null) {
            VALUES("update_time", "#{updateTime,jdbcType=TIMESTAMP}");
        }

        return SQL();
    }

    public String updateByPrimaryKey(ConsoleCorpInfo entity) {
        BEGIN();
        UPDATE(TABLE_NAME);

        if (entity.getFullName() != null) {
            SET("full_name = #{fullName,jdbcType=VARCHAR}");
        }

        if (entity.getShortName() != null) {
            SET("short_name = #{shortName,jdbcType=VARCHAR}");
        }

        if (entity.getEmail() != null) {
            SET("email = #{email,jdbcType=VARCHAR}");
        }

        if (entity.getTelephone() != null) {
            SET("telephone = #{telephone,jdbcType=VARCHAR}");
        }


        if (entity.getMealPackage() != null) {
            SET("meal_package = #{mealPackage,jdbcType=VARCHAR}");
        }

        if (entity.getRegisterDate() != null) {
            SET("register_date = #{registerDate,jdbcType=TIMESTAMP}");
        }

        if (entity.getAbateDate() != null) {
            SET("abate_date = #{abateDate,jdbcType=TIMESTAMP}");
        }

        if (entity.getUpdateTime() != null) {
            SET("update_time = #{updateTime,jdbcType=TIMESTAMP}");
        }

        WHERE("id = #{id,jdbcType=INTEGER}");

        return SQL();
    }

}
